#include "../tools.h"

/**
 * 给定一个整数，编写一个算法将这个数转换为十六进制数。
 * 对于负整数，我们通常使用 补码运算 方法。
 * 
 * Input: 26 Output: "1a"
 * Input: -1 Output: "ffffffff"
 */

class Solution {
public:

    string toHex(int num) {
        if (num == 0) return "0";
        vector<char> d = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

        char res[100] = {0};
        int n = 0;
        uint nnum = num;
        while(nnum != 0){
            int id = nnum & 15;
            
            res[n++] = d[id];
            nnum >>= 4;
        }

        int nn = n/2;
        for(int i = 0; i < nn; ++i){
            swap(res[i], res[n - 1 - i]);
            cout << res << std::endl;
        }
        
        return res;
    }
};


int main(int argc, char const *argv[])
{
    Solution s;
    cout << s.toHex(26);



    return 0;
}
